﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：RabbitMqModule.cs
// 功能描述：TongTongMall.RabbitMq
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Castle.MicroKernel.Registration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Commanding.Messaging;
using TongTongMall.Dependecy;
using TongTongMall.Modules;
using TongTongMall.RabbitMq.RabbitMq;

namespace TongTongMall.RabbitMq
{
    [DependsOn(typeof(KernelModule))]
    public class RabbitMqModule : BaseModule
    {
        public override void Initialize()
        {

            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());


            var configuration = IocManager.Resolve<IRabbitMqConfiguration>();

            if (configuration.IsEnabled)
            {
                //生产MQ消息
                IocManager.IocContainer.Register(Component.For(typeof(ICommandSender)).ImplementedBy(typeof(RabbitMqCommandSender)).DependsOn(new Hashtable {
                        { "uri",configuration.RabbitMqUrlString},{ "exchangeName",configuration.ExchangeName}}).LifestyleTransient());

                //消费Mq消息
                IocManager.IocContainer.Register(Component.For(typeof(IMessageSubscriber)).ImplementedBy(typeof(RabbitMqMessageSubscriber)).DependsOn(new Hashtable { { "uri", configuration.RabbitMqUrlString }, { "exchangeName", configuration.ExchangeName }, { "queueName", configuration.QueueName } }).LifestyleTransient());
            }
        }
    }
}
